package com.xie.authority_system.controller;

import com.xie.authority_system.config.qiniu.QiniuUtils;
import com.xie.authority_system.utils.Result;
import jakarta.annotation.Resource;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author 谢金成
 * @date 2024/1/30 20:56
 */
@RestController
@RequestMapping("/api/qiniu/file")
public class UploadController {
    @Resource
    private QiniuUtils qiniuUtils;

    @PostMapping("/upload")
    public Result upload(@RequestBody MultipartFile file, String module, String avatar) {
        if (!ObjectUtils.isEmpty(avatar)) {
            qiniuUtils.delete(avatar);
        }
        String url = qiniuUtils.upload(file, module);
        return Result.ok(url).message("文件上传成功");
    }
}
